/*   **********************************************************************  **
 **   Copyright notice                                                       **
 **                                                                          **
 **   (c) 2009, Around(J2)ME				                                 **
 **   All rights reserved.                                                   **
 **                                                                          **
 **   This program and the accompanying materials are made available under   **
 **   the terms of the New BSD License which accompanies this    			 **
 **   distribution.											                 **
 **   A copy is found in the textfile LICENSE.txt							 **
 **                                                                          **
 **   This copyright notice MUST APPEAR in all copies of the file!           **
 **                                                                          **
 **   Main developers:                                                       **
 **     Juri Strumpflohner		http://blog.js-development.com	             **
 **		Matthias Braunhofer		http://matthias.jimdo.com                    **
 **                                                                          **
 **  **********************************************************************  */

package org.aroundme.model;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/**
 * Utility class for handling dates (parsing, etc...)
 */
public class DateManager {
	private Locale locale;
	
	public DateManager(){
		 locale = Locale.ENGLISH;
	}
	
	/**
	 * 
	 * @return Date object containing the current date
	 */
	public Date getCurrentDate(){
		Date date = new Date();
		return date;
	}
	
	/**
	 * Returns the default DateFormatter for Simple Dates, e.g. dd.MM.yyy
	 * @return SimpleDateFormat
	 */
	public SimpleDateFormat getSimpleDateFormatter(){
		SimpleDateFormat bartDateFormat = new SimpleDateFormat("dd.MM.yyyy");
		return bartDateFormat;
	}
	
	/**
	 * Parses a given date as String to a Date object
	 * @param dateString = dateString to convert
	 * @return Date object
	 */
	public Date parseDate(String dateString){
		SimpleDateFormat formatter = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy", locale);
		Date d = null;
        try {
			d = (Date)formatter.parse(dateString);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return d;
	}
	
	/**
	 * Creates a simple date by passing the string in the
	 * format "dd.mm.yyyy"
	 * @param dateString = String representing date "dd.mm.yyyy"
	 * @return Date object containing the date specified in the param "dateString"
	 */
	public Date createSimpleDate(String dateString){
		SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy", locale);
		Date d = null;
        try {
			d = (Date)formatter.parse(dateString);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return d;
	}
}
